package h0815;

import java.util.Comparator;
import java.util.HashMap;
import java.util.Scanner;
import java.util.StringJoiner;
import java.util.function.Consumer;

/**
 * @author 不知名帅哥
 * @version 1.0
 * @description 数组去重和排序
 * @date 2024/8/14 23:54
 */
public class ArraySortedRemoveDuplicate {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] arr = sc.nextLine().split(",");
        System.out.println(getResult(arr));
    }

    public static String getResult(String[] arr) {
        HashMap<String, Integer> count = new HashMap<>();
        HashMap<String, Integer> first = new HashMap<>();

        for (int i = 0; i < arr.length; i++) {
            String s=arr[i];
            count.put(s,count.getOrDefault(s,0)+1);
            first.putIfAbsent(s,i);
        }

        StringJoiner sj = new StringJoiner(",");

        first.keySet().stream().sorted(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                Integer a = count.get(o1);
                Integer b = count.get(o2);
                if (!a.equals(b)){
                    return Integer.compare(b,a); //从大到小
                }else {
                    return first.get(o1).compareTo(first.get(o2));
                }
            }
        }).forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                sj.add(s);
            }
        });

        return sj.toString();
    }
}